﻿Imports System.Web.UI.WebControls.Expressions
Module modCommon

    Public Function getMsgStr(ByVal msgId As String, Optional ByVal args1 As String = "", Optional ByVal args2 As String = "", Optional ByVal args3 As String = "") As String

        If String.IsNullOrEmpty(args1) AndAlso String.IsNullOrEmpty(args2) AndAlso String.IsNullOrEmpty(args3) Then
            getMsgStr = htMsgMst(msgId)
            Exit Function

        ElseIf Not String.IsNullOrEmpty(args1) AndAlso Not String.IsNullOrEmpty(args2) AndAlso String.IsNullOrEmpty(args3) Then
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2)
            Exit Function
        ElseIf Not String.IsNullOrEmpty(args1) AndAlso Not String.IsNullOrEmpty(args2) AndAlso Not String.IsNullOrEmpty(args3) Then
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2, args3)
            Exit Function
        Else
            getMsgStr = String.Format(htMsgMst(msgId), args1, args2)
            Exit Function
        End If

    End Function

    ''' <summary>
    ''' 检查是否为空
    ''' </summary>
    ''' <param name="Sender">要检查的控件</param>
    ''' <returns></returns>
    Public Function chkEmpty(Sender As Object) As Boolean
        If Sender.text = "" Then
            MsgBox(getMsgStr("msg001", Sender.tag))
            Sender.Select()
            Return False
        End If
        Return True
    End Function

    ''' <summary>
    ''' 检查是否大于0
    ''' </summary>
    ''' <param name="Sender">要检查的控件</param>
    ''' <returns></returns>
    Public Function chkEmptyNum(Sender As Object) As Boolean
        If Val(Sender.text) < 1 Then
            MsgBox(getMsgStr("msg002", Sender.tag))
            Sender.Select()
            Return False
        End If
        Return True
    End Function

    Public Sub setMstComboBox(cmb As ComboBox, mstXH As String)
        Dim objMstList As New clsMstList
        Dim dt As DataTable
        If mstXH = "01" Then
            Dim objMstFlbList As New clsFlbMst
            dt = objMstFlbList.getAllList()
        ElseIf mstXH = "02" Then
            Dim objMstGjbList As New clsGjbMst
            dt = objMstGjbList.getAllList()
        Else
            dt = objMstList.selectByType(mstXH, False)
        End If
        cmb.DisplayMember = "mst_name"
        cmb.ValueMember = "size"
        cmb.DataSource = dt
    End Sub

    Public Sub setMstChkList(chl As DevExpress.XtraEditors.CheckedListBoxControl, mstXH As String)
        Dim objMstList As New clsMstList
        Dim dt As DataTable
        dt = objMstList.selectByType(mstXH, False)

        If dt.Rows.Count > 0 Then
            For i As Integer = 0 To dt.Rows.Count - 1
                chl.Items.Add(dt.Rows(i)("mst_value"))
            Next
        End If
    End Sub

    Public Sub setAllErrMsg()
        'メッセージが取得済みの場合は設定しない
        If htMsgMst.Count = 0 Then
            Dim objmsg As New clsMessage
            Dim dtMsgMst As DataTable = objmsg.GetAllMsg()
            For Each dr In dtMsgMst.Rows
                With htMsgMst
                    .Add(dr("msg_id"), dr("msg"))
                End With
            Next
        End If
    End Sub

End Module
